<template>
    <a-modal
      :title="title"
      :width="600"
      :visible="visible"
      :confirmLoading="confirmLoading"
      @ok="handleOk"
      @cancel="handleCancel"
      cancelText="关闭"
    >
    <a-spin :spinning="confirmLoading">
      <a-form-model ref="form" :model="model" :rules="validatorRules">
        <a-form-model-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="title"
          label="标题名称">
          <a-input placeholder="请输入标题名称" v-model="model.title"/>
        </a-form-model-item>
        <a-form-model-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="brandId"
          label="品牌">
           <a-select v-model="model.brandId" placeholder="品牌" show-search>
            <a-select-option :value="item.id" v-for="item in brandList" :key="item.id"> {{ item.brandName }} </a-select-option>
          </a-select>
        </a-form-model-item>
        <a-form-model-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="remark"
          label="备注">
          <a-textarea v-model="model.remark" :rows="4" />
        </a-form-model-item>
        <a-form-model-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          prop="status"
          label="状态">
          <!-- <a-input v-model="model.description"/> -->
          <a-radio-group v-model="model.status" name="radioGroup" @change="change">
            <a-radio :value="0">启用</a-radio>
            <a-radio :value="1">禁用</a-radio>
          </a-radio-group>
        </a-form-model-item>
      </a-form-model>
    </a-spin>
    </a-modal>
</template>

<script>
  import { saveOrUpdateRenovation,brandList} from '@/api/marketingCenter/newmember'
  export default {
    name:'cc',
    components: {},
    data() {
        let describe =  (rule, value, callback) => {
          if(value.length == ''){
            callback(new Error('请输入商品描述！'))
          }else if(value.length > 200){
                callback(new Error('请控制在200个字符内！'))
            }else{
                callback()
            }
        };
      return {
        brandList: [],
        value: 1,
        title: '操作',
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 }
        },
         wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 }
        },
        confirmLoading: false,
        validatorRules: {
          title: [{ required: true, message: '请输入商品标题!' }],
          brandId: [{ required: true, message: '请选择品牌!' }],
          // remark: [{ validator:describe,required: true}],
          status: [{ required: true, message: '请选择状态!' }],
          
          },
      }
    },
    created() {
    },
    methods: {
      //品牌下拉
    getBrandList() {
      brandList({
        current: 0,
        size: 99,
        state: 1
      })
        .then(res => {
          if (res.code === 200) {
            this.brandList = res.data
          } else {
            this.$message.error(res.msg || res.message)
          }
        })
        .catch(err => {})
    },
    add() {
        this.edit({
          status: 0
        })
      },
      handleChange(value) {
        this.model.status = value
      },
      change(e){
        console.log(e.target.value);
      },
      edit(record) {
        this.getBrandList()
        if (record.id) {
          this.visiblekey = true
        } else {
          this.visiblekey = false
        }
        this.model = Object.assign({}, record)
        this.visible = true
      },
      // 确定
      handleOk() {
        const that = this
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true
            let obj
            var addObject={
              title:this.model.title,
              brandId:this.model.brandId,
              remark:this.model.remark,
              status:this.model.status,
            }
            if (this.model.id) {
              addObject.id=this.model.id
            }
              console.log(this.model);
            saveOrUpdateRenovation(addObject).then((res) => {
              if (res.success) {
                that.$message.success(res.msg)
                that.$emit('ok')
              } else {
                that.$message.warning(res.msg)
              }
            }).finally(() => {
              that.confirmLoading = false
              that.close()
            })
          } else {
            return false;
          }
        })
      },
      // 关闭
      handleCancel() {
        this.close()
      },
      close() {
        this.$emit('close')
        this.fileList = []
        this.visible = false
        this.$refs.form.resetFields();
      },
    }
  }
</script>
<style scoped>
.divList{
  border-bottom: 1px solid #ccc;
  padding-left: 34px;
  margin-bottom: 30px;
  position: relative;
}
.bairuidelete{
  position:absolute;
  top: 135px;
  right: 80px;
  width: 20px;
  height: 20px;
}

</style>